package edu.biwu.mapper;

import edu.biwu.po.OrderDetail;
import edu.biwu.po.Product;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface OrderDetailMapper {

//    @Select("SELECT product_id,product_num FROM mybatis02.order_detail WHERE order_id = #{orderId}") 一对多时写的代码
    @Results({
            @Result(column = "product_id",property = "productId"),
            @Result(property = "product",javaType = Product.class,column = "product_id",
            one=@One(select = "edu.biwu.mapper.ProductMapper.findById",fetchType = FetchType.LAZY))
    })
    @Select("SELECT product_id,product_num FROM mybatis02.order_detail WHERE order_id = #{orderId}")
    List<OrderDetail> findByOrderId(int orderId);
}

